<template>
    <div id="examplepage">
        <ul>
            <li v-for="(item,index) of files" :key="index" class="example-item">
                <span>{{index + 1}}、{{item.split('.')[0]}}</span>
                <a @click="show(item)">查看</a>
                <a :href="`/api/examples/${item}`">下载</a>
            </li>
        </ul>
    </div>
</template>

<script>
    import axios from 'axios';
	export default {
		name: "examplepage",
        async asyncData({app}){
		    let result = await app.$getFiles();
		    let files = result.data;
		    return {
		    	files
            }
        },
        methods:{
			async show(name){
				let result = await axios.get(`/api/examples/${name}`);
				let newPage = window.open('about:blank','_blank');
				setTimeout(()=>{
					newPage.document.write(result.data);
                },100);
            }
        }
	}
</script>

<style scoped>
    #examplepage{
        background-color: #FFFFFF;
        padding: 10px;
        margin: 20px auto;
    }
    a{
        font-size: 13px;
        text-decoration: underline;
        margin-left: 10px;
    }
    a:hover{
        cursor: pointer;
        color:#5974AB;
    }
    .example-item{
        display: flex;
        justify-content: center;
        align-items: center;
        line-height: 30px;
        margin: 10px auto;
        background-color: #E5E8E9;
    }
    .example-item > span{
        display: inline-block;
        width: 150px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
    }
    @media screen and (min-width: 1000px){
        #examplepage{
            margin-top: 70px;
            width: 1000px;
            min-height: 800px;
        }
    }
    @media screen and (min-width: 750px) and (max-width: 1000px){
        #examplepage{
            margin-top: 70px;
            width: 95%;
            min-height: 800px;
        }
    }
    @media screen and (max-width: 750px){
        #examplepage{
            margin-top: 60px;
            width: 95%;
        }
        span{
            font-size: 14px;
        }
    }
</style>